import threading
import time


def run():
    for i in range(10):
        print("task", i)
        time.sleep(1)       #此时子线程停1s
        print('3')
        time.sleep(1)
        print('2')
        time.sleep(1)
        print('1')


t = threading.Thread(target=run)
t.setDaemon(True)   #把子进程设置为守护线程，必须在start()之前设置, 档主线程退出后，子线程也退出
t.start()

time.sleep(10)     #主线程停0.5秒
print(threading.active_count()) #输出活跃的线程数